package com.ruoyi.web.controller.vantController.customerController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.domain.customer.LocalReply;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.BrandInfo;
import com.ruoyi.system.domain.zhuangxiumain.vo.ResviersVo;
import com.ruoyi.system.service.vantservice.customerervice.ApiLocalService;
import com.ruoyi.system.utils.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 本地评论前端接口
 *
 * @author 张少丛
 */
@Api(value = "前端本地评论接口", tags = {"前端本地评论接口"})
@RestController
@RequestMapping("/api/customer/reviers")
@CrossOrigin
public class ApiLocalReviersController extends BaseController {

    @Autowired
    private ApiLocalService localReviersService;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private TokenUtils tokenUtils;

    /**
     * 查询本地评论列表
     * @return
     */
    @ApiOperation(value = "查询本地评论列表")
    @GetMapping("/selectLocalReviersList")
    public AjaxResult selectLocalReviersList() {
        return AjaxResult.success(localReviersService.selectLocalReviersList());
    }

    /**
     * 查询本地评论回复列表
     * @return
     */
    @ApiOperation(value = "查询本地评论回复列表")
    @GetMapping("/selectLocalReplyList/{localReviersId}")
    public AjaxResult selectLocalReplyList(@PathVariable(value = "localReviersId", required = false) Long localReviersId) {
        return AjaxResult.success(localReviersService.selectLocalReplyList(localReviersId));
    }

    /**
     * 添加评论信息
     * @param localReply
     * @return
     */
    @ApiOperation(value = "添加评论信息")
    @PostMapping("/addLocalReply")
    public AjaxResult addLocalReply(@RequestBody LocalReply localReply){
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        localReply.setLocalReplyCustomer(customerLogin.getCustomerId());
        return AjaxResult.success(localReviersService.addLocalReply(localReply));
    }

    /**
     * 根据发布信息id查询回复
     * @return
     */
    @PostMapping("/replyVo/{localReviersId}")
    public AjaxResult replyVoByReviersId(@PathVariable("localReviersId") Integer localReviersId ){
        return AjaxResult.success(localReviersService.selectReplyVoByRevierwsId(localReviersId));
    }

    /**
     * 查询本地发布的全部信息（哈哈哈哈）
     * @param resviersVo
     * @return
     */
    @PostMapping("/resviersVo")
    public AjaxResult resviersVo(@RequestBody ResviersVo resviersVo){
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        resviersVo.setLocalReviewsUser(Integer.parseInt(String.valueOf(customerLogin.getCustomerId())));
        return AjaxResult.success(localReviersService.selectResviersVo(resviersVo));
    }

    /**
     * 消息中的评论
     * @return
     */
    @PostMapping("/newsReviersVo")
    public AjaxResult newsReviersVo(){
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        ResviersVo resviersVo = new ResviersVo();
        resviersVo.setCustomerId(Integer.parseInt(String.valueOf(customerLogin.getCustomerId())));
        return AjaxResult.success(localReviersService.selectNewsReviersVo(resviersVo));
    }

    /**
     * 消息中的点赞
     * @return
     */
    @PostMapping("/newsReviersVoTwo")
    public AjaxResult newsReviersVoTwo(){
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        ResviersVo resviersVo = new ResviersVo();
        resviersVo.setCustomerId(Integer.parseInt(String.valueOf(customerLogin.getCustomerId())));
        return AjaxResult.success(localReviersService.selectNewsReviersVoTwo(resviersVo));
    }

}
